package com.candy.th7;
public class Child extends Thread{

    private Kitchen kitchen;
//属性：体力值，默认为0，即没吃饭的状态
    private int hp=0;
    //健康值，吃饱后健康值和体力值相等
    private int health;

    public Child(String name, Kitchen kitchen, int health) {
        super(name);
        this.kitchen = kitchen;
        this.health = health;
    }

    public void eat(){
        try {
            //吃饭操作
            this.kitchen.do_eat();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void run() {
        //当体力值小于健康值的时候 说明没吃饱 可以一直进行吃饭行为，直到吃饱了为止
        while(this.hp<this.health){
            this.eat();
        }
        System.out.println(this.getName()+"吃饱了....");
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }
}
